RNA-Seq: Pathway analysis using cameraPR and fGSEA

cameraPR

Function

cameraPR <- function(statistic, index, use.ranks = FALSE, inter.gene.cor = 0.01, sort = TRUE, ...) {
  dots <- names(list(...))
  if (length(dots)) warning("Extra arguments disregarded: ", sQuote(dots))

  #     Check statistic
  if (is.list(statistic)) stop("statistic should be a numeric vector")
  storage.mode(statistic) <- "numeric"
  if (anyNA(statistic)) stop("NA values for statistic not allowed")
  G <- length(statistic)
  ID <- names(statistic)
  if (G < 3) stop("Too few genes in dataset: need at least 3")

  #     Check index
  if (!is.list(index)) index <- list(set1 = index)
  index <- index[which(!sapply(index, function(x) length(x) < 10))] # ADDED BY ASA 190527 to mimic fgsea minSize = 10
  nsets <- length(index)

  #     Check inter.gene.cor
  if (anyNA(inter.gene.cor)) stop("NA inter.gene.cor not allowed")
  if (any(abs(inter.gene.cor) >= 1)) stop("inter.gene.cor too large or small")
  if (length(inter.gene.cor) > 1L) {
    if (length(inter.gene.cor) != nsets) stop("Length of inter.gene.cor doesn't match number of sets")
    fixed.cor <- FALSE
  } else {
    fixed.cor <- TRUE
    inter.gene.cor <- rep_len(inter.gene.cor, nsets)
  }

  #     Set df
  if (use.ranks) {
    df.camera <- Inf
  } else {
    df.camera <- G - 2L
  }

  #     Global statistics
  meanStat <- mean(statistic)
  varStat <- var(statistic)
  tst <- c() ### ADDED BY ASA on 190514
  NGenes <- Down <- Up <- rep_len(0, nsets)
  for (i in 1:nsets) {
    iset <- index[[i]]
    if (is.character(iset)) iset <- which(ID %in% iset)
    StatInSet <- statistic[iset]
    m <- length(StatInSet)
    NGenes[i] <- m
    if (use.ranks) {
      p.value <- rankSumTestWithCorrelation(iset,
        statistics = statistic,
        correlation = inter.gene.cor[i], df = df.camera
      )
      Down[i] <- p.value[1]
      Up[i] <- p.value[2]
    } else {
      vif <- 1 + (m - 1) * inter.gene.cor[i]
      m2 <- G - m
      meanStatInSet <- mean(StatInSet)
      delta <- G / m2 * (meanStatInSet - meanStat)
      varStatPooled <- ((G - 1L) * varStat - delta^2 * m * m2 / G) / (G - 2L)
      two.sample.t <- delta / sqrt(varStatPooled * (vif / m + 1 / m2))
      tst[i] <- two.sample.t ### ADDED BY ASA on 190514
      Down[i] <- pt(two.sample.t, df = df.camera)
      Up[i] <- pt(two.sample.t, df = df.camera, lower.tail = FALSE)
    }
  }
  TwoSided <- 2 * pmin(Down, Up)
  #     Assemble into data.frame
  D <- (Down < Up)
  Direction <- rep_len("Up", nsets)
  Direction[D] <- "Down"
  if (fixed.cor) {
    tab <- data.frame(NGenes = NGenes, Direction = Direction, PValue = TwoSided, TwoSampT = tst, stringsAsFactors = FALSE)
  } ### ADDED TwoSampT on 190514
  else {
    tab <- data.frame(NGenes = NGenes, Correlation = inter.gene.cor, Direction = Direction, PValue = TwoSided, stringsAsFactors = FALSE)
  }
  rownames(tab) <- names(index)

  #     Add FDR
  if (nsets > 1L) tab$FDR <- p.adjust(tab$PValue, method = "BH")

  #     Sort by p-value
  if (sort && nsets > 1L) {
    o <- order(tab$PValue)
    tab <- tab[o, ]
  }

  tab
}

Results

## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()

## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()

## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()

## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()

## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()

## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()

## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()

## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()

## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()

Tables

PND8 vs PND15

fGSEA

c2

c6

c7

## Warning in instance$preRenderHook(instance): It seems your data is too
## big for client-side DataTables. You may consider server-side processing:
## https://rstudio.github.io/DT/server.html

Gene Ontology

GO_BP

GO_CC

GO_MF

KEGG

reactome

CameraPR

c2

c6

c7

Gene Ontology

GO_BP

GO_CC

GO_MF

KEGG

reactome

PND15 vs Adult

fGSEA

c2

c6

c7

## Warning in instance$preRenderHook(instance): It seems your data is too
## big for client-side DataTables. You may consider server-side processing:
## https://rstudio.github.io/DT/server.html

Gene Ontology

GO_BP

GO_CC

GO_MF

KEGG

reactome

CameraPR

c2

c6

c7

Gene Ontology

GO_BP

GO_CC

GO_MF

KEGG

reactome

Plots

c2

c6

c7

Gene Ontology

GO_BP

GO_CC

GO_MF

KEGG

reactome

SessionInfo

## ─ Session info ──────────────────────────────────────────────────────────
##  setting  value                       
##  version  R version 3.6.1 (2019-07-05)
##  os       Ubuntu 16.04.6 LTS          
##  system   x86_64, linux-gnu           
##  ui       X11                         
##  language (EN)                        
##  collate  de_DE.UTF-8                 
##  ctype    de_DE.UTF-8                 
##  tz       Europe/Zurich               
##  date     2019-09-30                  
## 
## ─ Packages ──────────────────────────────────────────────────────────────
##  package              * version   date       lib
##  acepack                1.4.1     2016-10-29 [1]
##  annotate               1.62.0    2019-05-02 [1]
##  AnnotationDbi        * 1.46.1    2019-08-20 [1]
##  assertthat             0.2.1     2019-03-21 [1]
##  backports              1.1.4     2019-04-10 [1]
##  base64enc              0.1-3     2015-07-28 [1]
##  Biobase              * 2.44.0    2019-05-02 [1]
##  BiocFileCache          1.8.0     2019-05-02 [1]
##  BiocGenerics         * 0.30.0    2019-05-02 [1]
##  BiocParallel         * 1.18.1    2019-08-06 [1]
##  Biostrings             2.52.0    2019-05-02 [1]
##  bit                    1.1-14    2018-05-29 [1]
##  bit64                  0.9-7     2017-05-08 [1]
##  bitops                 1.0-6     2013-08-17 [1]
##  blob                   1.2.0     2019-07-09 [1]
##  bookdown               0.13      2019-08-21 [1]
##  Cairo                  1.5-10    2019-03-28 [1]
##  callr                  3.3.2     2019-09-22 [1]
##  caTools                1.17.1.2  2019-03-06 [1]
##  checkmate              1.9.4     2019-07-04 [1]
##  circlize               0.4.8     2019-09-08 [1]
##  cli                    1.1.0     2019-03-19 [1]
##  clue                   0.3-57    2019-02-25 [1]
##  cluster                2.1.0     2019-06-19 [1]
##  codetools              0.2-16    2018-12-24 [1]
##  colorspace             1.4-1     2019-03-18 [1]
##  ComplexHeatmap         2.0.0     2019-05-02 [1]
##  crayon                 1.3.4     2017-09-16 [1]
##  crosstalk              1.0.0     2016-12-21 [1]
##  curl                   4.2       2019-09-24 [1]
##  data.table             1.12.2    2019-04-07 [1]
##  DBI                    1.0.0     2018-05-02 [1]
##  dbplyr                 1.4.2     2019-06-17 [1]
##  DelayedArray         * 0.10.0    2019-05-02 [1]
##  dendextend             1.12.0    2019-05-11 [1]
##  desc                   1.2.0     2018-05-01 [1]
##  DESeq2                 1.24.0    2019-05-02 [1]
##  devtools               2.2.0     2019-09-07 [1]
##  digest                 0.6.21    2019-09-20 [1]
##  dplyr                  0.8.3     2019-07-04 [1]
##  DT                   * 0.9       2019-09-17 [1]
##  edgeR                * 3.26.8    2019-09-01 [1]
##  ellipsis               0.3.0     2019-09-20 [1]
##  EnrichmentBrowser    * 2.14.3    2019-08-03 [1]
##  evaluate               0.14      2019-05-28 [1]
##  fastmatch              1.1-0     2017-01-28 [1]
##  fgsea                * 1.10.1    2019-08-21 [1]
##  foreach                1.4.7     2019-07-27 [1]
##  foreign                0.8-72    2019-08-02 [1]
##  Formula                1.2-3     2018-05-03 [1]
##  fs                     1.3.1     2019-05-06 [1]
##  gclus                  1.3.2     2019-01-07 [1]
##  gdata                  2.18.0    2017-06-06 [1]
##  genefilter             1.66.0    2019-05-02 [1]
##  geneplotter            1.62.0    2019-05-02 [1]
##  GenomeInfoDb         * 1.20.0    2019-05-02 [1]
##  GenomeInfoDbData       1.2.1     2019-07-24 [1]
##  GenomicRanges        * 1.36.1    2019-09-06 [1]
##  GEOquery               2.52.0    2019-05-02 [1]
##  GetoptLong             0.1.7     2018-06-10 [1]
##  ggplot2              * 3.2.1     2019-08-10 [1]
##  GlobalOptions          0.1.0     2018-06-09 [1]
##  glue                   1.3.1     2019-03-12 [1]
##  GO.db                  3.8.2     2019-07-24 [1]
##  gplots                 3.0.1.1   2019-01-27 [1]
##  graph                * 1.62.0    2019-05-02 [1]
##  gridExtra            * 2.3       2017-09-09 [1]
##  GSEABase               1.46.0    2019-05-02 [1]
##  GSVA                   1.32.0    2019-05-02 [1]
##  gtable                 0.3.0     2019-03-25 [1]
##  gtools                 3.8.1     2018-06-26 [1]
##  heatmaply            * 0.16.0    2019-05-11 [1]
##  highr                  0.8       2019-03-20 [1]
##  Hmisc                  4.2-0     2019-01-26 [1]
##  hms                    0.5.1     2019-08-23 [1]
##  htmlTable              1.13.2    2019-09-22 [1]
##  htmltools              0.3.6     2017-04-28 [1]
##  htmlwidgets            1.3       2018-09-30 [1]
##  httpuv                 1.5.2     2019-09-11 [1]
##  httr                   1.4.1     2019-08-05 [1]
##  IRanges              * 2.18.3    2019-09-24 [1]
##  iterators              1.0.12    2019-07-26 [1]
##  jsonlite               1.6       2018-12-07 [1]
##  KEGGgraph              1.44.0    2019-05-02 [1]
##  KEGGREST               1.24.0    2019-05-02 [1]
##  KernSmooth             2.23-15   2015-06-29 [1]
##  knitr                  1.25      2019-09-18 [1]
##  labeling               0.3       2014-08-23 [1]
##  later                  0.8.0     2019-02-11 [1]
##  lattice                0.20-38   2018-11-04 [1]
##  latticeExtra           0.6-28    2016-02-09 [1]
##  lazyeval               0.2.2     2019-03-15 [1]
##  lifecycle              0.1.0     2019-08-01 [1]
##  limma                * 3.40.6    2019-07-26 [1]
##  locfit                 1.5-9.1   2013-04-20 [1]
##  magrittr               1.5       2014-11-22 [1]
##  MASS                   7.3-51.4  2019-04-26 [1]
##  Matrix                 1.2-17    2019-03-22 [1]
##  matrixStats          * 0.55.0    2019-09-07 [1]
##  memoise                1.1.0     2017-04-21 [1]
##  mime                   0.7       2019-06-11 [1]
##  miniUI                 0.1.1.1   2018-05-18 [1]
##  multiGSEA            * 0.11.1    2019-01-29 [1]
##  munsell                0.5.0     2018-06-12 [1]
##  nnet                   7.3-12    2016-02-02 [1]
##  org.Mm.eg.db         * 3.8.2     2019-09-02 [1]
##  pillar                 1.4.2     2019-06-29 [1]
##  pkgbuild               1.0.5     2019-08-26 [1]
##  pkgconfig              2.0.3     2019-09-22 [1]
##  pkgload                1.0.2     2018-10-29 [1]
##  plgINS               * 0.1.5     2019-08-14 [1]
##  plotly               * 4.9.0     2019-04-10 [1]
##  plyr                   1.8.4     2016-06-08 [1]
##  png                    0.1-7     2013-12-03 [1]
##  prettyunits            1.0.2     2015-07-13 [1]
##  processx               3.4.1     2019-07-18 [1]
##  promises               1.0.1     2018-04-13 [1]
##  ps                     1.3.0     2018-12-21 [1]
##  purrr                  0.3.2     2019-03-15 [1]
##  questionr              0.7.0     2018-11-26 [1]
##  R6                     2.4.0     2019-02-14 [1]
##  rappdirs               0.3.1     2016-03-28 [1]
##  RColorBrewer           1.1-2     2014-12-07 [1]
##  Rcpp                 * 1.0.2     2019-07-25 [1]
##  RCurl                  1.95-4.12 2019-03-04 [1]
##  reactome.db            1.68.0    2019-07-24 [1]
##  readr                  1.3.1     2018-12-21 [1]
##  registry               0.5-1     2019-03-05 [1]
##  remotes                2.1.0     2019-06-24 [1]
##  reshape2               1.4.3     2017-12-11 [1]
##  rjson                  0.2.20    2018-06-08 [1]
##  rlang                  0.4.0     2019-06-25 [1]
##  rmarkdown              1.15      2019-08-21 [1]
##  rmdformats             0.3.5     2019-02-19 [1]
##  rpart                  4.1-15    2019-04-12 [1]
##  rprojroot              1.3-2     2018-01-03 [1]
##  RSQLite                2.1.2     2019-07-24 [1]
##  rstudioapi             0.10      2019-03-19 [1]
##  S4Vectors            * 0.22.1    2019-09-09 [1]
##  scales                 1.0.0     2018-08-09 [1]
##  seriation              1.2-8     2019-08-27 [1]
##  sessioninfo            1.1.1     2018-11-05 [1]
##  shape                  1.4.4     2018-02-07 [1]
##  shiny                  1.3.2     2019-04-22 [1]
##  shinythemes            1.1.2     2018-11-06 [1]
##  SparseM                1.77      2017-04-23 [1]
##  SRAdb                  1.46.0    2019-05-02 [1]
##  stringi                1.4.3     2019-03-12 [1]
##  stringr                1.4.0     2019-02-10 [1]
##  SummarizedExperiment * 1.14.1    2019-07-31 [1]
##  survival               2.44-1.1  2019-04-01 [1]
##  testthat               2.2.1     2019-07-25 [1]
##  tibble                 2.1.3     2019-06-06 [1]
##  tidyr                  1.0.0     2019-09-11 [1]
##  tidyselect             0.2.5     2018-10-11 [1]
##  topGO                  2.36.0    2019-05-02 [1]
##  TSP                    1.1-7     2019-05-22 [1]
##  usethis                1.5.1     2019-07-04 [1]
##  vctrs                  0.2.0     2019-07-05 [1]
##  viridis              * 0.5.1     2018-03-29 [1]
##  viridisLite          * 0.3.0     2018-02-01 [1]
##  webshot                0.5.1     2018-09-28 [1]
##  withr                  2.1.2     2018-03-15 [1]
##  writexl                1.1       2018-12-02 [1]
##  xfun                   0.9       2019-08-21 [1]
##  XML                    3.98-1.20 2019-06-06 [1]
##  xml2                   1.2.2     2019-08-09 [1]
##  xtable                 1.8-4     2019-04-21 [1]
##  XVector                0.24.0    2019-05-02 [1]
##  yaml                   2.2.0     2018-07-25 [1]
##  zeallot                0.1.0     2018-01-28 [1]
##  zlibbioc               1.30.0    2019-05-02 [1]
##  source                           
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  Bioconductor                     
##  Bioconductor                     
##  Bioconductor                     
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  Bioconductor                     
##  Bioconductor                     
##  Bioconductor                     
##  Bioconductor                     
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Github (lianos/multiGSEA@b8747ab)
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  local                            
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
##  CRAN (R 3.6.1)                   
##  CRAN (R 3.6.1)                   
##  Bioconductor                     
## 
## [1] /home/ubuntu/R/x86_64-pc-linux-gnu-library/3.6
## [2] /usr/local/lib/R/site-library
## [3] /usr/lib/R/site-library
## [4] /usr/lib/R/library

Deepak Tanwar

Created on: 2019-09-02
Updated on: 2019-09-30